﻿using PlayerScannerCore.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace PlayerScanner
{
    /// <summary>
    /// Interaction logic for FloorItems.xaml
    /// </summary>
    public partial class FloorItemsWindow : Window
    {
        private DispatcherTimer _timer;
        private FloorViewModel _viewModel;

        public FloorItemsWindow()
        {
            InitializeComponent();
            _timer = new DispatcherTimer() { Interval = new TimeSpan(0, 0, 1) };
            _timer.Tick += Timer_Tick;
            _timer.Start();
        }

        public FloorViewModel ViewModel
        {
            get { return _viewModel; }
            set { DataContext = _viewModel = value; }
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            if (IsVisible)
                ViewModel.Refresh();
        }

        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            //Prevent window closing. Simply hide the window instead.
            e.Cancel = true;
            base.OnClosing(e);

            Hide();
        }
    }
}
